<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script th:src="@{/layui/layui.js}"></script>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script th:src="@{/layui/layui.all.js}"></script>
</head>
<body>
<form method="post" th:action="@{/sys/info}">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        设置我的资料
<!-- 添加成功后返回  <p style="color:red;" th:text="${success}" th:if="${not #strings.isEmpty(success)}"></p>-->
                    </div>
                    <div class="layui-card-body" pad15>

                        <div class="layui-form" lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">我的角色</label>
                                <div class="layui-input-inline">
                                    <select name="role" lay-verify="">
                                        <option value="1" selected>超级管理员</option>
                                        <option value="2" disabled>普通管理员</option>
                                        <option value="3" disabled>审核员</option>
                                        <option value="4" disabled>编辑人员</option>
                                    </select>
                                </div>
                                <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">用户名</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="username" th:value="${admin.getUsername()}" readonly class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="nickname" th:value="${admin.getNickname()}" autocomplete="off"  class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">头像</label>
                                <div class="layui-inline">
                                    <input type="text" value="" id="pic_1_src" name="head" style="display: none;">
                                    <div class="layui-upload">
                                        <div class="layui-upload-list">
                                            <img class="layui-upload-img" id="pic_1" width="100" height="100" th:src="${admin.getHead()}">
                                            <p id="picText_1"></p>
                                        </div>
                                        <button type="button" class="layui-btn" id="upload_1">上传图片</button>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">手机</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="mobile"  th:value="${admin.getMobile()}" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="email"  th:value="${admin.getEmail()}" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" >确认修改</button>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/layui.all.js}"></script>
<script>
    layui.use('upload', function(){
        var $ = layui.jquery;
        var upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#upload_1'
            ,url: '/sys/uploadPictures'
            ,size:2048
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#pic_1').attr('src', result);
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败'+res);
                }
                //上传成功
                var demoText = $('#picText_1');
                demoText.html('<span style="color: #4cae4c;">上传成功</span>');
                //将后台获取的图片地址传到前台存入隐藏控件中，随着表单一起提交
                document.getElementById("pic_1_src").value = res.data.src;
                console.log("图片地址："+res.data.src);
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        })
    });
</script>
</body>
</html>